package classes.controlers {
	import classes.utils.trtb.xmlLoader.XMLLoader;
	import classes.utils.trtb.xmlLoader.XMLLoaderEvent;
	import flash.net.URLVariables;
	import classes.global.Global_Properties;
	
	/**
	 * ...
	 * @author Kihoonee
	 */
	public class XML_Controler {
		
		private var main:Main;
		
		private var myRankLoader:XMLLoader;
		private var rankLoader:XMLLoader;
		
		
		public function XML_Controler( _main:Main ) {
			main = _main;
			
			myRankLoader = new XMLLoader();
			myRankLoader.addEventListener(XMLLoaderEvent.LOAD_COMPLETE, myRankLoaderLOAD_COMPLETE );
			myRankLoader.addEventListener(XMLLoaderEvent.LOAD_FAIL, LOAD_FAIL );
			
			rankLoader = new XMLLoader();
			rankLoader.addEventListener(XMLLoaderEvent.LOAD_COMPLETE, rankLoaderLOAD_COMPLETE );
			rankLoader.addEventListener(XMLLoaderEvent.LOAD_FAIL, LOAD_FAIL );
		}
		
		public function load():void {
			myRankLoader.url = "http://chocohana.com/include/rabbitTownRank.php";
			
			var params:URLVariables = new URLVariables();
			params.cmdType = "23";
			params.gameCode = "rg01";
			params.score = Global_Properties.score;
			params.userKey = Global_Properties.keyCode;
			params.coinQnt = Global_Properties.coin;
			
			myRankLoader.load( params );
		}
		
		private function LOAD_FAIL(e:XMLLoaderEvent):void {
			trace("LOAD_FAIL : ", e.errorReason);
		}
		
		private function myRankLoaderLOAD_COMPLETE(e:XMLLoaderEvent):void {
			main.rank.myData( myRankLoader.xml );
			
			rankLoader.url = "http://chocohana.com/include/rabbitTownRank.php";
			var params:URLVariables = new URLVariables();
			params.cmdType = "25";
			params.gameCode = "rg01";
			params.rankRange1 = 1;
			params.rankRange2 = 101;
			
			rankLoader.load( params );
		}
		
		private function rankLoaderLOAD_COMPLETE(e:XMLLoaderEvent):void {
			main.rank.rankData(rankLoader.xml);
			main.viewChange( "rank_mc" )
		}
		
	}

}